package Model;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import Dao.RequestTransferDao;
import Dao.ViewRequestDao;
import Entity.Transfer;

public class ViewRequestModel extends AbstractTableModel {
	private String[] header = { "ID","Number", "Name","FromLocation",
			"ToLocation","FromProject", "ToProject","FromDepartment", "ToDepartment"};
	private List<Transfer> transferList = new Vector<Transfer>();
	
//	public ViewRequestModel(){
////		transferList.addAll(dao.searchApproval());
//		transfer();
//	}
	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return header.length;
	}

	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return transferList.isEmpty() == true ? 0 : transferList.size();
	}
	@Override
	public String getColumnName(int column) {
		// TODO Auto-generated method stub
		return header[column];
	}
	@Override
	public Object getValueAt(int row, int col) {
		// TODO Auto-generated method stub
		if (transferList.isEmpty())
			return null;
		Transfer item = transferList.get(row);
		switch (col) {
		case 0:
			return item.getID();
		case 1:
			return item.getEmpNumber();
		case 2:
			return item.getEmpName();
		case 3:
			return item.getFromLocation();
		case 4:
			return item.getToLocation();
		case 5:
			return item.getFromProject();
		case 6:
			return item.getToProject();
		case 7:
			return item.getFromDepartment();
		case 8:
			return item.getToDepartment();
		default:
			return null;
		}
	}
	
	
	public void transfer() throws IOException, ClassNotFoundException, SQLException{
		transferList = ViewRequestDao.searchApproval();
		fireTableDataChanged();
	}
}
